package com.example.news.controller;

import com.example.news.pojo.form.BasePageQuery;
import com.example.news.pojo.form.CommentForm;
import com.example.news.pojo.form.UpdateCommentForm;
import com.example.news.pojo.vo.AllCommentVo;
import com.example.news.pojo.vo.FirstCommentVo;
import com.example.news.pojo.vo.MyCommentVo;
import com.example.news.pojo.vo.SecondCommentVo;
import com.example.news.service.CommentService;
import com.example.news.utils.result.PageResult;
import com.example.news.utils.result.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/comment")
@Tag(name = "6.评论模块")
public class CommentController {
    @Autowired
    private CommentService commentService;

    @GetMapping("/myList")
    @Operation(summary = "获取自己的评论")
    public PageResult<MyCommentVo> getMyCommentList(@RequestHeader String token, @ParameterObject BasePageQuery basePageQuery){
        return commentService.getMyComment(token,basePageQuery);
    }

    @GetMapping("/firstCommentList/{id}")
    @Operation(summary = "获取一级评论")
    public PageResult<FirstCommentVo> getFristCommentList(@PathVariable Integer id, @ParameterObject BasePageQuery basePageQuery){
        return commentService.getFirstCommentByArticleId(id,basePageQuery);
    }

    @GetMapping("/secondCommentList/{id}")
    @Operation(summary = "获取二级评论")
    public PageResult<SecondCommentVo> getSecondCommentList(@PathVariable Integer id, @ParameterObject BasePageQuery basePageQuery){
        return commentService.getSecondCommentByFirstId(id,basePageQuery);
    }

    @GetMapping("/allComment")
    @Operation(summary = "获取全部评论（管理员）")
    public PageResult<AllCommentVo> getAllComment(@RequestHeader String token, @ParameterObject BasePageQuery basePageQuery, String key){
        return commentService.getALlComment(basePageQuery,token,key);
    }

    @PostMapping("/one")
    @Operation(summary = "添加评论")
    public Result<String> addComment(@RequestBody CommentForm commentForm){
        return commentService.addComment(commentForm);
    }

    @PutMapping("/one")
    @Operation(summary = "更新评论(管理员）")
    public Result<String> updateComment(@RequestBody UpdateCommentForm updateCommentForm){
        return commentService.updateComment(updateCommentForm);
    }

    @DeleteMapping("/one/{id}")
    @Operation(summary = "删除评论")
    public Result<String> deleteComment(@PathVariable Integer id){
        return commentService.deleteComment(id);
    }
}
